package com.egghiro.framework.j2se.game.core.view.window;

import java.awt.BorderLayout;
import java.awt.Frame;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
import java.awt.event.KeyAdapter;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import com.egghiro.framework.j2se.game.core.SGSystem;
import com.egghiro.framework.j2se.game.core.view.canvas.SGameCanvas;

public class GameFrame extends Frame {
    // TODO NOT GameCanvas But Screen
    private SGameCanvas screen;

    public GameFrame(SGameCanvas canvas) {
        screen = canvas;
        add(screen, BorderLayout.CENTER);
        addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                GameFrame.this.close(e);
            }

            @Override
            public void windowActivated(WindowEvent e) {
                GameFrame.this.windowActivated(e);
            }
        });
        addFocusListener(new FocusAdapter() {
        	@Override
        	public void focusGained(FocusEvent e){
        		focuseScreen();        		
        	}
		});
        
        // TODO NOT SCREEN BUT handler
        screen.setKeyListener();
        pack();
    }

    private void windowActivated(WindowEvent e) {
        focuseScreen();
    }

    private void close(WindowEvent e) {
        SGSystem.exit();
    }
    
    private boolean focuseScreen(){
    	return screen.requestFocusInWindow();
    }

}
